package flc.ast.adapter;

import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.bean.StkResBean;

public class MovieAdapter extends StkProviderMultiAdapter<StkResBean> {

    public MovieAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new MovieProvider());
    }

    private int type=0;//0 近期热门/猜你喜欢 1搜索 2必看榜单

    public void setType(int type){
        this.type=type;
    }

    private class MovieProvider extends BaseItemProvider<StkResBean> {
        @Override
        public int getItemViewType() {
            return SelPictureAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_movie;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, StkResBean bean) {
            Glide.with(getContext()).load(bean.getThumbUrl())
                    .into((ImageView) baseViewHolder.getView(R.id.ivMovieItemImg));
            baseViewHolder.setText(R.id.tvMovieItemName,bean.getName());
            baseViewHolder.setText(R.id.tvMovieItemDesc,bean.getDesc());
            if (type==2){
                baseViewHolder.setVisible(R.id.tvMovieItemLog,true);
                int rank=baseViewHolder.getBindingAdapterPosition()+1;
                baseViewHolder.setText(R.id.tvMovieItemLog,rank+"");
                if (rank<=3){
                    baseViewHolder.setBackgroundResource(R.id.tvMovieItemLog,R.drawable.icon_bq1);
                    baseViewHolder.setTextColor(R.id.tvMovieItemLog, Color.parseColor("#FFFFFFFF"));
                }else if (rank<=5){
                    baseViewHolder.setBackgroundResource(R.id.tvMovieItemLog,R.drawable.icon_bq2);
                    baseViewHolder.setTextColor(R.id.tvMovieItemLog, Color.parseColor("#FFB999FE"));
                }else {
                    baseViewHolder.setVisible(R.id.tvMovieItemLog,false);
                }
            }else{
                baseViewHolder.setVisible(R.id.tvMovieItemLog,false);
            }
            if (type==1){
                baseViewHolder.getView(R.id.tvMovieItemDesc).setVisibility(View.INVISIBLE);
            }
        }
    }

}
